package com.xishu.controller;

import com.xishu.annotation.valid.Admin;
import com.xishu.annotation.valid.MethodValidator;
import com.xishu.config.Config;
import com.xishu.entity.plat.GlobalSetting;
import com.xishu.response.ResponseData;
import com.xishu.service.CommonService;
import com.xishu.service.GlobalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "平台全局配置")
@RestController
public class GlobalSettingController {
    private CommonService commonService = CommonService.getInstance();
    private Config config = Config.getInstance();

    @ApiOperation(value = "搜索全局设置")
    @PutMapping(value = ("/global/setting"), produces = ("application/json;charset=UTF-8"))
    @MethodValidator(mustLogin = false)
    public ResponseData queryGlobalSetting() throws Exception {
        return commonService.createResponse(GlobalService.getInstance().getGlobalSetting());
    }

    @ApiOperation(value = "修改全局设置")
    @Admin
    @PutMapping(value = ("/global/setting/modify"), produces = ("application/json;charset=UTF-8"))
    public ResponseData modifyGlobalSetting(@RequestBody GlobalSetting globalSetting) throws Exception {
        return commonService.modifyObject(globalSetting);
    }

    @ApiModelProperty(value = "查询DOLA版本号")
    @PutMapping(value = ("/dola/version"), produces = ("application/json;charset=UTF-8"))
    @MethodValidator(mustLogin = false)
    public ResponseData dolaVersion() throws Exception {
        return commonService.createResponse(config.dolaShowVersion());
    }
}
